using System;
using GameFramework;
using UnityEngine;
using GameFramework.Fsm;

namespace LS.Fsm
{
    public abstract class LoaderBaseState<TOwner> : FsmState<TOwner>, IReference where TOwner : class, ILoaderOwner
    {
        public abstract float Progress { get; }
        public abstract bool IsFinish { get; }
        public abstract bool IsSuccess { get; }
        public virtual Type NextState { get; set; } = null;
        
        protected void ChangeToNextState(IFsm<TOwner> fsm)
        {
            var owner = fsm.Owner;
            if (NextState != null)
            {
                ChangeState(fsm, NextState);
            }
            owner.LoadFinish();
        }

        protected override void OnDestroy(IFsm<TOwner> fsm)
        {
            base.OnDestroy(fsm);
            ReferencePool.Release(this);
        }

        public virtual void Clear()
        {
            NextState = null;
        }
    }
}
